//
//  PrivateMTableViewCell.m
//  jingdongfang
//
//  Created by yons on 16/10/18.
//  Copyright © 2016年 ZhiYu Hao. All rights reserved.
//

#import "PrivateMTableViewCell.h"

@interface PrivateMTableViewCell ()

@property (strong, nonatomic) UIImageView *iconImageView;

@property (strong, nonatomic) UILabel *nameLab;
@property (strong, nonatomic) UILabel *contentLab;
@property (strong, nonatomic) UILabel *timeLab;
@property (strong, nonatomic) UILabel *numlab;

@end

@implementation PrivateMTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // 这三句代码可以代替- (void)setSelected:(BOOL)selected animated:(BOOL)animated
        UIView *view = [[UIView alloc] initWithFrame:self.multipleSelectionBackgroundView.bounds];
        //gcx-私信view点击背景效果修改
        view.backgroundColor =RGB(222,222,222);
        self.selectedBackgroundView = view;
        // 这个属性是编辑的时候最右边的accessory样式
        //    self.editingAccessoryType = UITableViewCellAccessoryCheckmark;
        
        [self _initView];
    }
    return self;
}

- (void)_initView {
    _iconImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
    [self.contentView addSubview:_iconImageView];
    
    _nameLab = [[UILabel alloc] initWithFrame:CGRectZero];
    _nameLab.font = [UIFont font14];
    _nameLab.textColor=[UIColor c4Color];
    [self.contentView addSubview:_nameLab];
    
    _contentLab = [[UILabel alloc] initWithFrame:CGRectZero];
    _contentLab.font = [UIFont font12];
    _contentLab.textColor=[UIColor c5Color];
    [self.contentView addSubview:_contentLab];
    
    _timeLab = [[UILabel alloc] initWithFrame:CGRectZero];
    _timeLab.font = [UIFont font12];
    _timeLab.textColor=[UIColor c5Color];
    [self.contentView addSubview:_timeLab];
    
    _numlab = [[UILabel alloc] initWithFrame:CGRectZero];
    _numlab.textColor = [UIColor whiteColor];
    _numlab.font = [UIFont font12];
    [self.contentView addSubview:_numlab];
}

- (void)setSiXinModel:(ImMsgModel *)siXinModel {
    [_iconImageView sd_setImageWithURL:[NSURL URLWithString:siXinModel.senderImg] placeholderImage:[UIImage imageNamed:@"place_head_Icon"]];
    _nameLab.text = siXinModel.senderNick;
    if ([siXinModel.type integerValue] == 2) {
//        _contentLab.text = @"[图片]";
        _contentLab.text = [NSString stringWithFormat:@"[%@]",NSLocalizedString(@"Picture", nil)];
    } else {
        _contentLab.text = siXinModel.content;
    }
    _timeLab.text = [NSDate timestampToString:siXinModel.createAt Format:@"MM-dd"];
    
    if(siXinModel.count && [siXinModel.count integerValue] != 0) {
        _numlab.text = [NSString stringWithFormat:@"%@", siXinModel.count];
        _numlab.hidden = NO;
    } else {
        _numlab.hidden = YES;
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    if (self.editing) {
        if (selected) {
            // 取消多选时cell成蓝色
            //            self.contentView.backgroundColor = [UIColor whiteColor];
            //            self.backgroundView.backgroundColor = [UIColor whiteColor];
            
        }else{
            
        }
    }
}


-(void)layoutSubviews
{
    [super layoutSubviews];
    
    _iconImageView.frame = CGRectMake(10, 10, 40, 40);
    _iconImageView.centerY = self.height/2;
    
    [_nameLab sizeToFit];
    _nameLab.left = _iconImageView.right + 10;
    _nameLab.top = _iconImageView.top;
    
    [_timeLab sizeToFit];
    _timeLab.centerY=self.centerY;
    _timeLab.right = self.width - 10;
    _timeLab.height=60;
    _timeLab.y=0;
    _timeLab.numberOfLines=2;
    
    [_contentLab sizeToFit];
    _contentLab.bottom = _iconImageView.bottom;
    _contentLab.right = KSCREENWIDTH-10;
    _contentLab.left = _iconImageView.right + 10;
    _contentLab.width = KSCREENWIDTH -10 - _iconImageView.right - 10-_timeLab.width;

    
    
    _numlab.frame = CGRectMake(0, 0, 16, 16);
    _numlab.top = _iconImageView.top;
    _numlab.right = _iconImageView.right + 8;
    
    _numlab.backgroundColor = [UIColor redColor];
    _numlab.layer.cornerRadius = _numlab.width/2;
    _numlab.layer.masksToBounds = YES;
    _numlab.textAlignment = NSTextAlignmentCenter;
    
    
    _iconImageView.layer.cornerRadius = _iconImageView.width/2;
    _iconImageView.layer.masksToBounds = YES;
    [_nameLab sizeToFit];
    if (_nameLab.right > _timeLab.left-10) {
        _nameLab.width = _timeLab.left-10-_nameLab.left;
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

@end
